package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/03/18 20:10
 **/
public class Day3_18_Num1616 {
    class Solution {
        public boolean checkPalindromeFormation(String a, String b) {
            String a_ = new StringBuilder(a).reverse().toString();
            String b_ = new StringBuilder(b).reverse().toString();
            return checkPalindromeFormation_(a,b) || checkPalindromeFormation_(b,a)
                    || checkPalindromeFormation_(a_,b_) || checkPalindromeFormation_(b_,a_);
        }
        private boolean checkPalindromeFormation_(String a,String b){
            int left = 0 , right = a.length()-1;
            while(left < right){
                if(a.charAt(left) != b.charAt(right)){
                    if(b != a){
                        b = a;
                        continue;
                    }
                    return false;
                }
                left++;
                right--;
            }
            return true;
        }
    }
}